﻿Imports System.Data
Imports VSModel
Imports Cls_Common

Partial Class Control_Hotel_ThongTinChung
    Inherits System.Web.UI.UserControl
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

            hidID.Value = Session("HotelId")
            ShowData()

        End If
    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            Dim p As Hotel = (From q In data.Hotels Where q.Id = hidID.Value Select q).SingleOrDefault
            If Not p Is Nothing Then
                lblHotelname.Text = IIf(IsNothing(p.HotelName) = True, "", p.HotelName)
                If Not p.HotelTypeId Then
                    lblHoteltypeid.Text = (From k In data.HotelTypes Where k.HotelTypeId = p.HotelTypeId Select k.Title).FirstOrDefault
                End If
                lblAddress.Text = IIf(IsNothing(p.Address) = True, "", p.Address)

                If Not p.Ward Is Nothing AndAlso Not p.District Is Nothing Then

                    lblAddress.Text = lblAddress.Text & ", " & p.Ward & ", " & p.District

                End If



                txtBusinesslicence.Text = IIf(IsNothing(p.BusinessLicence) = True, "", p.BusinessLicence)
                txtNumberofroom.Text = IIf(IsNothing(p.NumberOfRoom) = True, "", p.NumberOfRoom)
                txtNumberofstaff.Text = IIf(IsNothing(p.NumberOfStaff) = True, "", p.NumberOfStaff)
                txtDirector.Text = IIf(IsNothing(p.Director) = True, "", p.Director)
                txtPhone.Text = IIf(IsNothing(p.Phone) = True, "", p.Phone)
                txtFax.Text = IIf(IsNothing(p.Fax) = True, "", p.Fax)
                txtEmail.Text = IIf(IsNothing(p.Email) = True, "", p.Email)
                txtWebsite.Text = IIf(IsNothing(p.WebSite) = True, "", p.WebSite)

            End If
        End Using
    End Sub
#End Region

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Using data As New VSEntities

            Dim p As Hotel = (From q In data.Hotels Where q.Id = hidID.Value).SingleOrDefault
            If Not p Is Nothing Then

                Try
                    p.BusinessLicence = txtBusinesslicence.Text.Trim()

                    Dim _NumberOfRoom As Integer
                    Try
                        _NumberOfRoom = CInt(txtNumberofroom.Text.Trim())
                    Catch ex As Exception
                        _NumberOfRoom = 0
                    End Try

                    Dim _NumberOfStaff As Integer
                    Try
                        _NumberOfStaff = CInt(txtNumberofstaff.Text.Trim())
                    Catch ex As Exception
                        _NumberOfStaff = 0
                    End Try

                    p.NumberOfRoom = _NumberOfRoom
                    p.NumberOfStaff = _NumberOfStaff

                    p.Director = txtDirector.Text.Trim()
                    p.Phone = txtPhone.Text.Trim()
                    p.Fax = txtFax.Text.Trim()
                    p.Email = txtEmail.Text.Trim()
                    p.WebSite = txtWebsite.Text.Trim()

                    Dim _Modifier As String = Session("UserName")
                    p.Modifier = _Modifier
                    p.Modified = Now
                    data.SaveChanges()


                    Excute_Javascript("Alertbox('Cập nhật thông tin khách sạn thành công.');", Me.Page, True)
                    ShowData()
                Catch ex As Exception

                    Excute_Javascript("Alertbox('Cập nhật thông tin khách sạn thất bại. Hãy kiểm tra lại đường truyền');", Me.Page, True)
                End Try
            End If
        End Using
    End Sub

    Protected Sub btnHuy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        ShowData()
    End Sub
End Class
